# -*- coding:utf-8 -*-
#2022/1/20 10:49
# author:xwl

from fastapi import APIRouter, Depends

from backend.app.app.api.api_Xiong.crud.pri_crud import well_input_save, save_well_input_data, \
    read_well_cal_input, read_well_cal_output, read_data_well_cal_data
from backend.app.app.api.api_Xiong.models.x_model import input_data_recovery_save
from backend.app.app.api.api_v1.user import verify_token_user

well_input = APIRouter(prefix="/well_input", tags=["单井措施方案经济评价输入数据"])


@well_input.post("/save", name="存库")
async def save(data:input_data_recovery_save,ver = Depends(verify_token_user)):
    result1 = well_input_save(data.User_ID,data.Proj_ID,data.Data)
    save_input_result,save_output_result = save_well_input_data(data.User_ID,data.Proj_ID,data.Inputdata, data.Outputdata)
    return {
        'save_data': result1 if result1 else {},
        'save_input_result':save_input_result if save_input_result else {},
        'save_output_result':save_output_result if save_output_result else {},
        'verify': ver
    }

@well_input.post("/return_data", name="返回")
async def return_data(User_ID,Proj_ID,ver = Depends(verify_token_user)):
    input_result = read_well_cal_input(User_ID, Proj_ID)
    output_result = read_well_cal_output(User_ID, Proj_ID)
    data = read_data_well_cal_data(User_ID, Proj_ID)
    return {
        'input_result': input_result,
        'output_result': output_result,
        'Data': data,
        'verify': ver
    }